package com.telecom.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import jakarta.annotation.Resource;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 充值号生成器
 * 
 * 基于雪花算法生成唯一充值号，格式为：RCG + 日期 + 雪花算法ID
 * 例：RCG20250116123456789012345678
 * 
 * @author GWX.cz
 * @since 2025-08-04
 */
@Component
@Slf4j
public class RechargeNumberGenerator {
    
    @Resource
    private SnowflakeIdGenerator snowflakeIdGenerator;
    
    /**
     * 充值号前缀
     */
    private static final String RECHARGE_PREFIX = "RCG";

    /**
     * 生成充值号
     * 
     * @return 唯一充值号
     */
    public String generateRechargeNumber() {

        // 生成雪花算法ID，直接拼接
        long snowflakeId = snowflakeIdGenerator.nextId();
        
        // 组装充值号：前缀 + 雪花ID
        String rechargeNumber = RECHARGE_PREFIX + snowflakeId;
        
        log.debug("生成充值号: {}, 雪花算法ID: {}", rechargeNumber, snowflakeId);
        
        return rechargeNumber;
    }
}